﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="BillManaga6.aspx.cs" Inherits="Admin_BillManaga"
    ValidateRequest="false" EnableViewStateMac="false" EnableEventValidation="false"
    ViewStateEncryptionMode="Never" %>

<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>upex</title>
    <link href="../css/main-admin.css" rel="stylesheet" type="text/css" />
    <link href="../css/contextmenu.css" rel="stylesheet" type="text/css" />
    <link href="../css/ui-lightness/jquery-ui-1.7.2.custom.css" rel="stylesheet" type="text/css" />

    <script src="../Jscript/jquery-1.3.2.min.js" type="text/javascript"></script>

    <script src="../Jscript/jquery-ui-1.7.2.min.js" type="text/javascript"></script>

    <script src="../Jscript/page.js" type="text/javascript"></script>

    <script src="../Jscript/SepSet.js" type="text/javascript"></script>

    <script src="../Jscript/jquery.contextmenu.js" type="text/javascript"></script>

    <script type="text/javascript">
        var m = false;
        var mx, my;
        $(document).ready(function() {

            $("#showselect").draggable();

            $(".trans-search-sep").hide();
            var option = { width: 0, items: [
                           { text: "全选", icon: "../images/icons/add_1.gif", alias: "selectall", action: menuAction }, { text: "反选", icon: "../images/icons/return.gif", alias: "selectfx", action: menuAction }, { type: "splitLine" }, { text: "品名编辑", icon: "../images/icons/disk.png", alias: "name", action: menuAction }, { text: "价格编辑", icon: "../images/icons/disk.png", alias: "price", action: menuAction }, { text: "其他编辑", icon: "../images/icons/disk.png", alias: "other", action: menuAction }, { text: "更换LOGO", icon: "../images/icons/disk.png", alias: "logo", action: menuAction }, { text: "货运状态", icon: "../images/icons/disk.png", alias: "state", action: menuAction }, { type: "splitLine" }, { text: "批量删除", icon: "../images/icons/cross.png", alias: "del", action: menuAction }, { text: "批量打印", icon: "../images/icons/pdf.gif", alias: "print", action: menuAction }, { text: "导出选择数据", icon: "../images/icons/xls.gif", alias: "excel", action: menuAction }, { text: "导出查询出的数据", icon: "../images/icons/xls.gif", alias: "selecttoexcel", action: menuAction}], onShow: applyrule
            };


            $("body").contextmenu(option);
            var h = $(document).height();

            window.parent.document.getElementById("mainshow").style.height = h + "px";
            $("#body").mousemove(function(e) {
                var od = $("#showselect");
                if (m) {
                    var mrx = e.clientX - mx;
                    var mry = e.clientY - my;

                    od.style.left = parseInt(od.style.left) + mrx + "px";
                    od.style.top = parseInt(od.style.top) + mry + "px";

                    mx = e.clientX;
                    my = e.clientY;
                }
            });
            $("#showselect").mousedown(function(e) {

                m = true;
                mx = e.clientX;
                my = e.clientY;

            });
            $("#showselect").mouseup(function(e) {
                m = false;

            });

        });
        function menuAction() {


            switch (this.data.alias) {
                case "selectall":
                    selectall();
                    break;
                case "selectfx":
                    selectFX();
                    break;
                case "name":
                    EditValue('name');
                    break;
                case "price":
                    EditValue('price');
                    break;
                case "other":
                    EditValue('other');
                    break;
                case "logo":
                    EditValue('logo');
                    break;
                case "del":
                    EditValue('del');
                    break;
                case "print":
                    EditValue('print');
                    break;


                case "selecttoexcel":
                    EditValue('selecttoexcel');
                    break;
                case "excel":
                    EditValue('toexcel');
                    break;
                case "state":
                    EditValue('state');
                    break;

            }


        }
        function applyrule(menu) {

            menu.applyrule({ name: "all",
                disable: true,
                items: []
            });

        }
        function BeforeContextMenu() {
            return this.id != "target3";
        }
        function ToCk(no) {


            if ($("#div" + no).css("display") == "none") {

                //  $(".trans-search-sep").hide();


                //  $(".iamgeclass").attr("src", "../images/arr-down-s.gif");

                $("#Imag" + no).attr("src", "../images/arr-up-s.gif");
                $("#div" + no).show();

                // var h = window.parent.document.getElementById("mainshow").style.height.replace("px", "");

                //  var all = parseInt(h) + 50 + $("#div" + no).innerHeight();

                var h = $(document).height();

                window.parent.document.getElementById("mainshow").style.height = h + "px";
            }
            else {
                var h = $("#div" + no).height();
                $("#Imag" + no).attr("src", "../images/arr-down-s.gif");
                $("#div" + no).hide();

                var lh = $(document).height() - h;

                window.parent.document.getElementById("mainshow").style.height = lh + "px";
            }


        }

        function Ckbox(no) {

    
            if ($("#ckb" + no).attr("checked") == true) {

                $("#div" + no + " input").attr("checked", true);

            }
            else {

                $("#div" + no + " input").attr("checked", false);

            }
            CrtDiv();

        }

        function CrtDiv() {
            var sep = "";
            var tno = "";


            $("input[type=checkbox]").each(function() {

                if ($(this).attr("checked") == true) {

                    var tn = $(this).attr("title");

                    if (tn.indexOf('SepNo') > -1) {

                        sep += tn.replace('SepNo', '') + "<br/>";
                    }
                    else {
                        tno += tn + "<br/>";

                    }
                }
            });



            if (sep == "" && tno == "") {
                $("#showselect").hide();
                return;
            }
            var all = "";
            if (tno != "") {
                all = "<strong style='color:blue'> 您已经选择单据：</strong> <br/>" + tno;
            }
            if (sep != "") {
                all += "<strong style='color:red'>您已经选择分单：</strong> <br/>" + sep;
            }
            $("#showselect").show();

            $("#showselect").html(all);
        }

        var selectalltg = false;
        function selectall() {

            if (selectalltg == false) {
                selectalltg = true;
                $("input[ type='checkbox']").attr("checked", true);

            }
            else {
                selectalltg = false;
                $("input[ type='checkbox']").attr("checked", false);

            }
            CrtDiv();
        }
        function Sepck() {
            CrtDiv();
        }

        function selectFX() {
            $("input[type=checkbox]").each(function() {

                if ($(this).attr("checked") == true) {


                    $(this).attr("checked", false);
                }
                else {
                    $(this).attr("checked", true);
                }
            });
            CrtDiv();
        }
        function EditValue(tp) {


            if (tp == "selecttoexcel") {
                var sql = "1=1";

                if ($.trim($("#stno").val()) != "") {
                    sql += " and TrackingNo like'%" + $.trim($("#stno").val()) + "%'";
                }
                if ($.trim($("#recervertxt").val()) != "") {
                    sql += " and Receiver like'%" + $.trim($("#recervertxt").val()) + "%'";
                }

                if ($.trim($("#statetxt option:selected").val()) != "") {
                    sql += " and StateId= " + $.trim($("#statetxt option:selected").val());
                }
                if ($.trim($("#accnotxt").val()) != "") {
                    sql += " and Sender like'%" + $.trim($("#accnotxt").val()) + "%'";
                }

                if ($.trim($("#startime").val()) != "") {

                    sql += " and CreateDate  >= cast('" + $.trim($("#startime").val()) + "  00:00:00 " + "' as datetime)  ";
                }

                if ($.trim($("#endtime").val()) != "") {

                    sql += " and CreateDate  <= cast('" + $.trim($("#endtime").val()) + " 23:59:59' as datetime)  ";
                }




                if ($.trim($("#zzhtxt").val()) != "") {
                    sql += " and FlightNo   like'%" + $.trim($("#zzhtxt").val()) + "%'";

                }

                window.location = "BillToExcel.aspx?area=" + sql;
                return;
            }
            var tnvalue = '';
            $("input[type=checkbox]").each(function() {

                if ($(this).attr("checked") == true) {

                    tnvalue = tnvalue + "," + $(this).val();
                }
            });
            if (tnvalue == "") {
                OpenWindow("你并未选择到有单据");
            }
            else {

                switch (tp) {
                    case "name":
                        window.location = "NameEdte.aspx?no=" + tnvalue;
                        break;
                    case "logo":
                        window.location = "BillLogoPl.aspx?no=" + tnvalue;
                        break;
                    case "other":
                        window.location = "OtherEdit.aspx?no=" + tnvalue;
                        break;
                    case "price":
                        window.location = "PriceEdit.aspx?no=" + tnvalue;
                        break;

                    case "print":
                        window.location = "ToPdf.aspx?no=" + tnvalue;
                        break;
                    case "toexcel":
                        window.location = "BillToExcel.aspx?no=" + tnvalue;
                        break;
                    case "state":
                        window.location = "BillStatePl.aspx?no=" + tnvalue;
                        break;














                    case "del":
                        //                        var Tno = "";
                        //                        var ok = true;
                        //                        $("input[type=checkbox]").each(function() {

                        //                            if ($(this).attr("checked") == true) {

                        //                                var no = $(this).attr("title");

                        //                                if (no.indexOf("SepNo") == 0) {

                        //                                    var tnp = $(this).attr("id").replace("sep", "");

                        //                                    var notchose = 0;
                        //                                    $("#div" + tnp + "  input[type=checkbox]  ").each(function() {
                        //                                        if ($(this).attr("checked") == false) {

                        //                                            notchose = notchose + 1;
                        //                                        }

                        //                                    });

                        //                                    if (notchose == 1) {
                        //                                        ok = false;
                        //                                        if (Tno.indexOf(tnp) == -1) {
                        //                                            Tno += "," + tnp;
                        //                                        }
                        //                                    }
                        //                                }

                        //                            }
                        //                        });


                        //                        if (!ok) {
                        //                            OpenWindow("以下单据您还有1张分单未删除，当前设置不允许如此选择：<br/>" + Tno);
                        //                            return;
                        //                        }

                        if (confirm("是否删除当前选择单据？") == true) {
                            OpenWindow("单据删除中.....请勿关闭！");
                            $.post("DelBill.ashx", { Tno: tnvalue }, function(data) {

                                if (data == "ok") {

                                    OpenWindow("单据删除成功!页面将刷新");
                                    location.reload();
                                }
                                else {

                                    OpenWindow(data);
                                }

                            });
                        }
                        break;
                }
            }

        }

      
 
    </script>

</head>
<body style="height: 700px">

    <script type="text/javascript" src="../DatePicker/WdatePicker.js"></script>

    <form id="form1" runat="server">
    <div class="title"></div>
    <div style="color: #0066FF; margin-bottom: 25px;"></div>
    <div class="trans-search-title">
        <div class="trans-search-selall">
            <b onclick="selectall()" style="cursor: pointer">全选</b></div>
        <div class="trans-search-arr">
            &nbsp;</div>
        <div class="trans-search-no">
            货运单号</div>
        <div class="trans-search-status">
            货运状态</div>
        <div class="trans-search-sender">
            寄件人</div>
        <div class="trans-search-rec">
            收件人</div>
        <div class="trans-search-case">
            件数</div>
        <div class="trans-search-wt">
            磅</div>
        <div class="trans-search-ref">
            参考号</div>
        <div class="trans-search-type">
            运单类型</div>
        <div class="trans-search-price">
            价格</div>
        <div class="trans-search-date">
            制单时间</div>
    </div>
    <asp:Repeater ID="billlist" runat="server">
        <ItemTemplate>
            <%# ((Container.ItemIndex + 1) % 2) == 0 ? "<div    class='trans-search-line result-bg'>" : "<div    class='trans-search-line'>"%>
            <div class="trans-search-selall">
                <input type="checkbox" name="checkbox" id='ckb<%#Eval("TrackingNo")%>' onclick="Ckbox('<%#Eval("TrackingNo")%>')"
                    value='<%#Eval("TrackingNo")%>Num<%#Eval("Sep").ToString()=="1"?Eval("NoOfPiece").ToString():"0"%>'
                    title='<%#Eval("TrackingNo")%>' /></div>
            <div class="trans-search-arr mtop3">
                <%# Eval("sep").ToString() == "0" ? "" : "   &nbsp;<img class='iamgeclass'  src='../images/arr-down-s.gif' id=\"Imag" + Eval("TrackingNo").ToString() + "\" width='13' height='13' onclick=\"ToCk('" + Eval("TrackingNo").ToString() + "')\"  />"%>
            </div>
            <div class="trans-search-no mtop3">
                <a href='#'>
                    <%#Eval("TrackingNo")%></a></div>
            <div class="trans-search-status mtop3" title='<%#Eval("UPEXState")%>'>
                <%#  Ysb.Components.StrHelper.GetSubString(Eval("UPEXState").ToString(),5)%>
            </div>
            <div class="trans-search-sender mtop3" titil=' <%#Eval("Sender")%>'>
                <%#Ysb.Components.StrHelper.GetSubString(Eval("Sender").ToString(),4)%>
            </div>
            <div class="trans-search-rec mtop3" titil=' <%#Eval("Receiver")%>'>
                <%#Ysb.Components.StrHelper.GetSubString(Eval("Receiver").ToString(), 4)%>
            </div>
            <div class="trans-search-case mtop3">
                <%#Eval("NoOfPiece")%></div>
            <div class="trans-search-wt mtop3">
                <%# Eval("sep").ToString() == "0" ? Eval("ChargedWt").ToString() : Eval("SepChargedWt").ToString()%>
            </div>
            <div class="trans-search-ref mtop3">
                <%#Ysb.Components.StrHelper.GetSubString(Eval("FlightNo").ToString(), 10)%>
            </div>
            <div class="trans-search-type mtop3">
                <%#new BLL.WayBillService().GetCalTypeName(Eval("Memo1").ToString())%></div>
            <div class="trans-search-price mtop3">
                <%# Eval("sep").ToString() == "0" ? Eval("Total").ToString() : Eval("SepTotal").ToString()%>
            </div>
            <div class="trans-search-date mtop3">
                <%# Convert.ToDateTime(Eval("CreateDate").ToString()).ToShortDateString()%></div>
            <div class="trans-search-reuse mtop3">
                <a href='BillEdit.aspx?area=cy&tno=<%#Eval("TrackingNo") %>'></a></div>
            <div class="trans-search-track mtop3">
                <a href='zhuizong.aspx?id=<%#Eval("TrackingNo") %>'></a></div>
            <div class="trans-search-print mtop3">
                <a href='ToPdf.aspx?no=<%#Eval("TrackingNo") %>&&sep=false'>打印</a></div>
            <div class="trans-search-addsep mtop3">
                <a href="#" onclick="ToSetSep('<%#Eval("TrackingNo")%>')"></a></div>
            </div>
<div class="trans-search-sep" id='div<%#Eval("TrackingNo").ToString()%>'>
                <asp:Repeater ID="sep_list" runat="server" DataSource='<%#getrpro( Eval("TrackingNo").ToString()) %>'>
                    <ItemTemplate>
                        <div class="trans-search-line">
                            <div class="trans-search-selall">
                                <input type="checkbox" name="checkbox" id='sep<%#Eval("TrackingNo").ToString()%>'
                                    value='SepNo<%#Eval("SepNo")%>Tno<%#Eval("TrackingNo").ToString()%>' title='SepNo<%#Eval("SepNo")%>'
                                    onclick='Sepck()' /></div>
                            <div class="trans-search-arr mtop3">
                                &nbsp;</div>
                            <div class="trans-search-no mtop3">
                                <a href='#'>
                                    <%#Eval("SepNo")%></a></div>
                            <div class="trans-search-status mtop3">
                                <%#  Ysb.Components.StrHelper.GetSubString(Eval("SBState").ToString(), 5)%>
                            </div>
                            <div class="trans-search-sender mtop3">
                                <%#Ysb.Components.StrHelper.GetSubString(Eval("SendBy").ToString(), 4)%>
                            </div>
                            <div class="trans-search-rec mtop3">
                                <%#Ysb.Components.StrHelper.GetSubString(Eval("CHNReceiver").ToString(), 4)%>
                            </div>
                            <div class="trans-search-case mtop3">
                                <%#Eval("Pieces")%></div>
                            <div class="trans-search-wt mtop3">
                                <%#Eval("ChargedWt")%></div>
                            <div class="trans-search-ref mtop3">
                                <%#Eval("FlightNo")%></div>
                            <div class="trans-search-type mtop3">
                                <%#new BLL.WayBillService().GetCalTypeName(Eval("Memo1").ToString())%></div>
                            <div class="trans-search-price mtop3">
                                <%# Eval("Total")%></div>
                            <div class="trans-search-date mtop3">
                                <%#Convert.ToDateTime( Eval("CreateDate").ToString()).ToShortDateString()%></div>
                            <div class="trans-search-reuse mtop3">
                                &nbsp;</div>
                            <div class="trans-search-track mtop3">
                                <a href='Zhuizong.aspx?id=<%#Eval("SepNo") %>'>跟踪</a></div>
                            <div class="trans-search-seplogo mtop3">
                                <img src='../UpLoad/small/small<%#Eval("Logo") %>' width="53" height="13" />
                            </div>
                        </div>
                    </ItemTemplate>
                </asp:Repeater>
          </div>
        </ItemTemplate>
    </asp:Repeater>
    <div style="margin: 10px 0px 0px 3px;">&nbsp;&nbsp;
        <img src="../images/btn-printlot.gif" width="68" height="25" onclick="EditValue('print')" />
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
    <div class="trans-export"></div>
    <div class="trans-nav">
        <webdiyer:AspNetPager ID="NewsPage" runat="server" AlwaysShow="True" CustomInfoHTML="第%CurrentPageIndex%页，共%PageCount%页，每页%PageSize%条"
            OnPageChanged="NewsPage_PageChanged" PageIndexBoxType="TextBox" ShowPageIndexBox="Always"
            SubmitButtonText="" TextAfterPageIndexBox="" TextBeforePageIndexBox="跳页" Width="800px"
            FirstPageText="&lt;img src=&quot;../img/btn-first.jpg&quot; width=&quot;46&quot; height=&quot;21&quot; align=&quot;absmiddle&quot; /&gt;"
            LastPageText="&lt;img src=&quot;../img/btn-last.jpg&quot; width=&quot;46&quot; height=&quot;21&quot; align=&quot;absmiddle&quot; /&gt;"
            NextPageText="&lt;img src=&quot;../img/btn-next.jpg&quot; width=&quot;32&quot; height=&quot;21&quot; align=&quot;absmiddle&quot; /&gt;"
            PrevPageText="&lt;img src=&quot;../img/btn-prev.jpg&quot; width=&quot;32&quot; height=&quot;21&quot; align=&quot;absmiddle&quot; /&gt;"
            SubmitButtonClass="showsb" PageIndexBoxClass="pageindexbox" PageSize="20" UrlPaging="True">
        </webdiyer:AspNetPager>
    </div>
    <div id="showselect" style="display: none; width: 120px; position: absolute; z-index: 999;
        top: 150px; right: 0px; background-color: White; cursor: move; border: #6699ff 1px solid;
        padding: 5px 5px">
    </div>
    </form>
</body>
</html>
